class Solution:
    def checkIfCanBreak(self, s1: str, s2: str) -> bool:
        if len(s1) != len(s2):
            return False
        s1Array = list(s1)
        s1Array.sort()
        s2Array = list(s2)
        s2Array.sort()
        flag = 0
        for i in range(len(s1Array)):
            string1 = s1Array[i]
            string2 = s2Array[i]
            cur = ord(string1) - ord(string2)
            if cur > 0 and flag < 0:
                return False
            if cur < 0 and flag > 0:
                return False
            if cur != 0:
                flag = cur

        return True
